package com.kkb.dao;

import com.kkb.pojo.User;
import com.kkb.util.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapHandler;

import java.sql.SQLException;
import java.util.Map;

public class UserDao {
    QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());
    public void signUpHandler(User user) throws SQLException {
        String sql = "insert into tb_user values(?,?,?,?,?,?,?)";
        Object[] params = {
            user.getId(), user.getUsername(), user.getPassword(), user.getEmail(),
            user.getName(), user.getGender(), user.getBirthday()
        };
        this.queryRunner.update(sql, params);
    }

    public Map<String, Object> signInHandler(String username, String password) throws SQLException {
        String sql = "select * from tb_user where username = ? and password = ?";
        Object[] params ={username, password};

        Map<String, Object> result = this.queryRunner.query(sql, new MapHandler(), params);
        return result;
    }
}
